﻿using DevExpress.XtraGrid.Demos.util;
using Luna小店.DTO;
using Luna小店.service;
using mendian;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Luna小店.UC.套号管理.套号吊牌.service
{
    public class 套号吊牌Service
    {
        public static void post套号模板(OpenFileDialog ofd,String id)
        {
            String md5 = FileService.GetMD5HashFromFile(ofd.FileName);
            FileService.UploadRequest(
                    URL.接口url + "/print_template/saveTagTemplate?id=" + id + "&md5=" + md5,
                    ofd.FileName,
                    Path.GetFileName(ofd.FileName),
                    "multipartFile"
                    );
        }

        public static DTO套号吊牌模板 get根据类型获取不同模板(String id)
        {
            return
                FunctionHelper.JsonDeserialization<DTO套号吊牌模板>(
                    RestCall.httpGetMethod(
                        URL.接口url + "/print_template/getTagInfoById?id=" + id
                        )
                    );
        }

        public static List<StyleCategoryDTO> get款式大类别()
        {
            return
                FunctionHelper.JsonDeserialization<List<StyleCategoryDTO>>(
                    RestCall.httpGetMethod(
                        URL.接口url + "/style/getStyleCategoryAll"));
        }

        public static DTO套号吊牌一览 get套号吊牌打印内容ByOrderId(String orderId,String sessionId)
        {
            return
                FunctionHelper.JsonDeserialization<DTO套号吊牌一览>(
                    RestCall.httpGetMethod(
                        URL.接口url + "/barcode/generateTagPrintByOrderId?orderId=" + orderId + "&sessionId=" + sessionId));
        }

        public static void 吊牌扫码预入库(String inventoryNo)
        {
            RestCall.PostHttp(
                URL.接口url + "/inventory/preMTSStockIn",
                inventoryNo
                );
        }
        public static DTO返回 套号确认入库(String sessionId)
        {
            return
                FunctionHelper.JsonDeserialization<DTO返回>(
                    RestCall.httpGetMethod(
                        URL.接口url + "/inventory/confirmMTSStockIn?sessionId=" + sessionId
                        )
                    );
        }
        public static void 清理session(String sessionId)
        {
            RestCall.PostHttp(
                URL.接口url + "/inventory/clearMTSSession",
                sessionId
                );
        }
        public static Boolean 判断二次打印吊牌(String orderId)
        {
            return
                FunctionHelper.JsonDeserialization<Boolean>(
                    RestCall.httpGetMethod(
                        URL.接口url + "/barcode/verifyTagPrint?orderId=" + orderId
                        )
                    );
        }
    }

    public class DTO套号吊牌模板
    {
        public string id { get; set; }
        public string md5 { get; set; }
        public string filePath { get; set; }
        public DTO套号吊牌模板()
        {

        }
    }

    public class DTO套号吊牌一览
    {
        public List<String> inventoryNos { get; set; } = new List<string>();   //条形码
        public String materialCode { get; set; }  //面料号
        public String materialComposition { get; set; }   //面料成分
        public List<MeasureItemDTO> measureItemDTOS { get; set; } = new List<MeasureItemDTO>();
        public String orderId { get; set; } //订单Id
        public String orderNumber { get; set; }//订单号
        public String styleId { get; set; }  //款式Id
        public String styleNameCn { get; set; }   //款名
        public String styleSizeCd { get; set; }    //尺码
        public String sytleFabricId { get; set; }   //面料Id
        public DTO套号吊牌一览()
        {

        }
    }

    public class DTO套号吊牌
    {
        public String 吊牌项目 { get; set; }//数据源
        public String 成衣值 { get; set; }//
        public DTO套号吊牌(string 吊牌项目, string 成衣值)
        {
            this.吊牌项目 = 吊牌项目;
            this.成衣值 = 成衣值;
        }

    }
    /// <summary>
    /// 确认入库的返回值DTO
    /// </summary>
    public class DTO返回
    {
        public String errorCode { get; set; }
        public String errorMessage { get; set; }
        public DTO返回()
        {

        }
    }
    /// <summary>
    /// 打印吊牌扫码预入库DTO
    /// </summary>
    public class DTO条码
    {
        public String inventoryNo { get; set; }
        public Boolean flag { get; set; }
        public DTO条码(string inventoryNo)
        {
            this.inventoryNo = inventoryNo;
            this.flag = false;
        }
    }
}
